/*
 * @Author: LGW
 * @Date: 2019-05-29 09:15:42
 * @Last Modified by: LGW
 * @Last Modified time: 2020-01-13 16:25:11
 */

import axios from '../utils/axios';

/**
 * 本周环比上周
 * @param {String} id 公司名字
 * @param {String} dateOne 日期 '2019-1-1'
 */
export function getWeeksPower(id, date) {
  const post = {
    dateOne: date,
  };
  id && (post.id = id)
  return axios.post('/eng/whole/count', post).then(res => {
    if (res.code === 1) return res.data
    else throw res.msg;
  })
}

export function getMonthBuyElec(id) {
  return axios.post('/eng/whole/monthBuyElec', { id });
}

/**
 * 获取指定日期每小时的使用电量
 * @param {String} id 公司名字
 * @param {String} dateOne 日期1 如: '2019-1-1'
 * @param {String} dateTwo 日期2
 */
export function getDayPower(id, dateOne, dateTwo) {
  const post = {
    dateOne,
    dateTwo,
    id,
  };
  return axios.post('/eng/whole/electTb', post);
}

/**
 * 获取指定周期的电量占比
 * @param {String} id 公司名字
 * @param {String} dateOne 如: '2019-1'
 * @param {String} dateTwo
 */
export function getPowerForm(id, dateOne, dateTwo) {
  const post = {
    dateOne,
    dateTwo,
    id,
  };
  return axios.post('/eng/whole/constitute', post);
}

/**
 * 获取采集电量
 * @param {String} id 公司ID
 * @param {Number} year
 * @param {Number} month
 * @param {Number} day
 */
export function getElectCollection(id, year, month, day) {
  const post = {
    id,
    year,
    month,
    day,
  };
  return axios.post('/eng/lad/electCollection', post);
}

/**
 * 电量年月日分布图
 * @param {String} id 公司id
 */
export function getElectDistr(id) {
  return axios.post('/eng/lad/electDistr', { id });
}

/**
 * 周期电量分部接口
 * @param {String} id 公司id
 */
export function getElectCycle(id) {
  return axios.post('/eng/lad/electCycle', { id });
}

/**
 * 最大需-容量电费对比接口
 * @param {String} id 公司id
 * @param {String || Number} year 年份
 */
export function getElectCapa(id, year) {
  return axios.post('/eng/lad/electCapa', { id, year });
}

export function getDayBuyElec(id, year, month) {
  const post = {
    id,
    year,
    month,
  };
  return axios.post('/eng/whole/dayBuyElec', post);
}

/**
 * 电量电费汇总
 * @param {String} id 公司Id
 * @param {String} dateOne 周期开始时间 如：'2019-1-1'
 * @param {String} dateTwo 周期结束时间
 * @param {Number} page 页码
 * @param {Number} rows 一页的数据数
 */
export function getElectForm(id, year, month) {
  return axios.post('/eng/lad/electForm', { id, year, month })
}

export function getElectPrice(id, dateOne, dateTwo, page, rows) {
  return axios.post('/eng/lad/electPrice', { id, dateOne, dateTwo, page, rows })
}

/**
 * 获取变压器分布图
 * @author LXBsmile
 * @date 2020-01-13
 * @param {Number} clientId
 * @returns {Array} clientList
 */
export function getTransDis(clientId) {
  return axios.get('/eng/transformer/data/transDis', { params: { clientId } }).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

/**
 * 变压器负荷曲线
 * @param {String} id 公司id
 * @param {String || Date || Timestamp} date 时间
 * @param {String} name '配电房-变压器'
 */
export function getTraLoad(id, date, name) {
  const t = new Date(date);
  const a = name.split('-');
  const post = {
    id,
    year: t.getFullYear(),
    month: t.getMonth() + 1,
    day: t.getDate(),
    dstbtRoom: a[0],
    transformer: a[1],
  };
  return axios.post('/eng/tra/traLoad', post);
}

export function getTraFzAndRz(id, date, byq) {
  const t = new Date(date),
    a = byq.split('-'),
    post = {
      id,
      year: t.getFullYear(),
      month: t.getMonth() + 1,
      day: t.getDate(),
      dstbtRoom: a[0],
      transformer: a[1],
    };
  return axios.post('/eng/tra/traFzAndRz', post);
}
export function getTraWholeLoad(id, date, byq) {
  const t = new Date(date),
    a = byq.split('-'),
    post = {
      id,
      year: t.getFullYear(),
      month: t.getMonth() + 1,
      day: t.getDate(),
      dstbtRoom: a[0],
      transformer: a[1],
    };
  return axios.post('/eng/tra/traWholeLoad', post);
}

export function getRealKzValue(id, date, byq) {
  const t = new Date(date),
    a = byq.split('-'),
    post = {
      id,
      year: t.getFullYear(),
      month: t.getMonth() + 1,
      day: t.getDate(),
      dstbtRoom: a[0],
      transformer: a[1],
    };
  return axios.post('/eng/tra/realKzValue', post);
}

export function getRealTimePower(id, dateOne, dateTwo, dstbtRoom, transformer) {
  const post = {
    id,
    dateOne,
    dateTwo,
    dstbtRoom,
    transformer,
  };
  return axios.post('/eng/tra/realTimePower', post);
}

export function getRealLoadViwe(id, dateOne, dateTwo, dstbtRoom, transformer) {
  const post = {
    id,
    dateOne,
    dateTwo,
    dstbtRoom,
    transformer,
  };
  return axios.post('/eng/tra/realLoadViwe', post);
}

/**
 * 负载率（cos实际VScos=0.95）
 * @param {String} id 公司id
 * @param {String || Date || Timestamp} date 时间
 * @param {String} name 'substationId-transformerId'
 */
export function getRealTimePower95(id, date, name) {
  const t = new Date(date);
  const a = name.split('-');
  const post = {
    id,
    year: t.getFullYear(),
    month: t.getMonth() + 1,
    day: t.getDate(),
    substationId: a[0],
    transformerId: a[1],
  };
  return axios.post('/eng/tra/realTimePower95', post).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  });
}

export function getRealDifferValue(id, dateOne, dateTwo) {
  const post = {
    id,
    dateOne,
    dateTwo,
  };
  return axios.post('/eng/tra/realDifferValue', post);
}

export function getTraEconomicsScore(id) {
  return axios.post('/eng/tra/traEconomicsScore', { id });
}

/**
 * 综合损耗功率及电量变化
 * @author LXBsmile
 * @date 2019-11-29
 * @param {any} post
 * @param {Number} post.id 公司id
 * @param {Number} post.year year
 * @param {Number} post.month month
 * @param {Number} post.day day
 * @param {String} post.dstbtRoom 配电房
 * @param {String} post.transformer 变压器
 * @returns {Array}
 */
export function getRealZhgvPower(post) {
  return axios.post('eng/tra/realZhgvPower', post).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

/**
 * 电费变化
 * @author LXBsmile
 * @date 2019-11-29
 * @param {any} post
 * @param {Number} post.id 公司id
 * @param {Number} post.year year
 * @param {Number} post.month month
 * @param {String} post.dstbtRoom 配电房
 * @param {String} post.transformer 变压器
 * @returns {Array}
 */
export function getRealLossFee(post) {
  return axios.post('eng/tra/realLossFee', post).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

export function getScoreRank() {
  return axios.post('/eng/transformer/data/scoreRank', {}).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}
